package com.factory.absfactory.order;

import com.factory.absfactory.pizza.Pizza;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class OrderPizza {

    AbsFactory factory;

    //构造器
    public OrderPizza(AbsFactory absFactory){
        setFactory(absFactory);
    }

    // 设置工厂
    private void setFactory(AbsFactory factory) {
        Pizza pizza = null;
        String orderType = ""; //订购披萨的类型
        this.factory = factory;
        do {
            orderType = gettype();
            pizza = factory.createPizza(orderType); //抽象方法，由工厂子类去完成
            if(pizza != null) {
                // 输出pizza制作过程
                pizza.prepare();
                pizza.bake();
                pizza.cut();
                pizza.box();
            }else {
                System.out.println("订购失败");
                break;
            }
        }while (true);
    }

    //写一个方法，可以获取客户希望订购的披萨种类
    private String gettype() {
        try {
            BufferedReader strin = new BufferedReader(new InputStreamReader(System.in));
            System.out.println("input pizza type:");
            String str = strin.readLine();
            return str;
        } catch (IOException e){
            e.printStackTrace();
            return "";
        }
    }
}
